package opeartion;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        Scanner in=new Scanner(System.in);
        System.out.println("请输入想借图书的名字：");
        String name=in.nextLine();
        int size=bookList.getUsedSize();
        for (int i = 0; i < size; i++) {
            Book book= bookList.getBooks(i);
            if (book.getName().equals(name)){
                if(book.isBoroowed()==true){
                    System.out.println("借取失败！");
                    System.out.println("图书:"+name+"已经被借出");
                }
                else{
                    System.out.println("借取成功");
                    book.setBoroowed(true);
                    System.out.println(book);
                }
                return;
            }
        }
        System.out.println("借阅失败!");
    }
}
